﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using HRMSys.Model;
using HRMSys.DAL;

namespace HRMSys.UI
{
    /// <summary>
    /// LoginWindown.xaml 的交互逻辑
    /// </summary>
    public partial class LoginWindown : Window
    {
        public LoginWindown()
        {
            InitializeComponent();
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            string inUserName = txtUserName.Text;

            string sql = "select * from T_Operator where UserName=@UserName";
            SqlParameter userNameParam = new SqlParameter("@UserName", inUserName);
            Operator op = (new OperatorDAL()).GetUserByName(inUserName);
            if (op == null)
            {
                MessageBox.Show("用户名或密码错误!");
            }
            else 
            {
                string dbMD5 = op.Password;
                string myMD5 = pwdPassword.Password;
                if (dbMD5 == CommonHelper.GetMD5(myMD5 + "love514415@yahoo.com.cn"))
                {
                    MessageBox.Show("登录成功!");
                    DialogResult = true;
                }
                else 
                {
                    MessageBox.Show("用户名或密码错误!");
                }
            }
        }
    }
}
